<?php 
	$room_list = $this->room_list;
	$date = $this->date;
	$number_seat = $this->number_seat;
	
	$next_date = strtotime ( '+1 day' , strtotime ( $date ) ) ;
	$next_date = date ( 'Y-m-d' , $next_date);
	$prev_date = strtotime ( '-1 day' , strtotime ( $date ) ) ;
	$prev_date = date ( 'Y-m-d' , $prev_date);
	
	$current_date = date("Y-m-d");
	if($prev_date < $current_date)
		$prev_date = $current_date;
	
	$next_day_link = "/user/order/step2-crossday/start_date/" . $next_date . "/number_seat/" . $number_seat;
	$prev_day_link = "/user/order/step2-crossday/start_date/" . $prev_date . "/number_seat/" . $number_seat;
?>
<section class="grid_8" id="room-status">
	<div class="block-border"><div class="block-content">
		<h1>
			会議室の状態			
		</h1>
		
		<div class="block-controls">
			<ul class="controls-buttons">
				<li><a href="<?php echo $prev_day_link?>" title="前日"><img src="/images/icons/fugue/navigation-180.png" width="16" height="16"></a></li>
				<li class="sep"></li>
				<li class="controls-block"><strong><?php echo $date?></strong></li>
				<li class="sep"></li>
				<li><a href="<?php echo $next_day_link?>" title="後日"><img src="/images/icons/fugue/navigation.png" width="16" height="16"></a></li>
			</ul>
		</div>
		
		<ul class="planning no-margin">
			<li class="planning-header">
				<span><b>会議室</b></span>
				<ul>
					<li class="at-0">0</li>
					<li class="at-1">1</li>
					<li class="at-2">2</li>
					<li class="at-3">3</li>
					<li class="at-4">4</li>
					<li class="at-5">5</li>
					<li class="at-6">6</li>
					<li class="at-7">7</li>
					<li class="at-8">8</li>
					<li class="at-9">9</li>
					<li class="at-10">10</li>
					<li class="at-11">11</li>
					<li class="at-12">12</li>
					<li class="at-13">13</li>
					<li class="at-14">14</li>
					<li class="at-15">15</li>
					<li class="at-16">16</li>
					<li class="at-17">17</li>
					<li class="at-18">18</li>
					<li class="at-19">19</li>
					<li class="at-20">20</li>
					<li class="at-21">21</li>
					<li class="at-22">22</li>
					<li class="at-23">23</li>
				</ul>
			</li>
			
			<?php if($room_list):?>
			<?php 
				$cur_date = date("Y-m-d");
				$cur_hour = date("H");
				$cur_minute = date("i");
				$cur_minute = floor($cur_minute / 30) * 30;
				$cur_minute .= $cur_minute == 0 ? "0" : "";
				$cur_time = $cur_hour . "-" . $cur_minute;
			?>
			<?php foreach ($room_list as $room):?>
				<?php 
					$room_orders_str = "";
					$room_type = $room['type'] == ROOM_TYPE_MEETING_ROOM ? '会議室' : '会議ブース';
					$room_tip = $room_type . $room['code'] . "(" . $room['number_seat'] . "席," . $room['rent_price'] . "VND/30分)";
				?>
				<li>
					<a href="#" title="<?php echo $room_tip?>" class="with-tip" onclick="setMeetingRoom(<?php echo $room['id']?>);return false;">
						<img src="/images/icons/fugue/home.png" width="16" height="16">  <?php echo $room_type . $room['code']?>
					</a>
					<ul>
						<?php if($date == $cur_date):?>
							<li class="current-time at-<?php echo $cur_time?>"></li>
						<?php endif;?>
					
						<?php $order_list = $room['order_list'];?>
						<?php if($order_list):?>
							<?php foreach ($order_list as $order):?>
								<?php 
									$start_date = substr($order['start_time'], 0, 10);
									if($start_date < $date){
										$start_time = "00:00";
										$start_hour = "0";
										$start_minute = "00";
									}else{
										$start_time = substr($order['start_time'], 11, 5);
										$start_hour = substr($start_time, 0, 2);
										$start_minute = str_replace($start_hour . ":", "", $start_time);
										$start_hour = $start_hour >= 10 ? $start_hour : substr($start_hour, 1);
									}
									
									$end_date = substr($order['end_time'], 0, 10);
									if($end_date > $date){
										$end_time = "23:00";
										$end_hour = "23";
										$end_minute = "00";
										$end_hour = substr($end_time, 0, 2);
									}else{
										$end_time = substr($order['end_time'], 11, 5);
										$end_hour = substr($end_time, 0, 2);
										$end_minute = str_replace($end_hour . ":", "", $end_time);
										$end_hour = $end_hour >= 10 ? $end_hour : substr($end_hour, 1);
									}
									
									$class = "from-" . $start_hour;
									$class .= $start_minute == 0 ? "" : "-" . $start_minute;
									$class .= " to-" . $end_hour;
									$class .= $end_minute == 0 ? "" : "-" . $end_minute;
									
									$event_class = $start_date == $end_date ? "event-blue" : "event-green";
									$title = $start_date != $end_date ? $order['username'] . " (" . $order['start_time'] .  " ~ " . $order['end_time'] . ")"
																		: $order['username'] . " ($start_time ~ $end_time)";
								?>
								<li class="<?php echo $class?>">
									<a href="#" title="<?php echo $title?>" class="with-tip">
										<span class="<?php echo $event_class?>" style="width:100%">
											<?php echo $start_time?> - 
											<?php echo $end_time?>
										</span>
									</a>
								</li>
							<?php endforeach;?>
						<?php endif;?>
					</ul>
					<?php echo $this->formHidden("room_" . $room['id'] . "_orders", $room_orders_str)?>
				</li>
			<?php endforeach;?>
			<?php endif;?>
			
		</ul>
		<ul class="message no-margin">
			<li>
				<?php if(count($room_list) > 0):?>
					予約可能な会議室：<?php echo count($room_list)?>室
				<?php else:?>
					予約可能な会議室がありません。
				<?php endif;?>
			</li>
		</ul>
	</div></div>
</section>